package com.chen.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

// 客户端
public class ClientSocketTest {
    public static void main(String[] args) throws IOException {

        // 1、准备服务器地址和端口
        InetAddress serverIP = InetAddress.getByName("127.0.0.1");
        int port = 9999;
        // 2、创建Socket
        Socket socket = new Socket(serverIP, port);
        // 3、获取OutputStream，发送消息
        OutputStream os = socket.getOutputStream();
        os.write("Hello, World".getBytes());

        os.close();
        // socket需要关闭
        socket.close();

    }
}
